package com.ruoyi.rabbitMQ;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.order.domain.SysOrderOne;
import com.ruoyi.order.mapper.SysOrderOneMapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description:
 * @Author: 吕宇宏
 * @Date: 2024/7/29 11:02
 */

@RestController
@RequestMapping("/mq")
public class sendDemo {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private SysOrderOneMapper orderOneMapper;


    @PostMapping("/sendMQ")
    public void fanoutPublish() {
        String queue="direct.queue01";   //这个queue必须被定义的，在bean中声明
        String message="fuck you nam!!";
        rabbitTemplate.convertAndSend(queue,message);   //两个参数指定队列
    }


    @PostMapping("/sendMQ02")
    public void fanoutPublish02(HttpServletResponse response, HttpServletRequest request) {
        SysOrderOne orderOne = orderOneMapper.selectSysOrderOneById(128l);




        String surveyRequestDTOString = JSONObject.toJSONString(orderOne);

        //发送调用执行背调接口
        rabbitTemplate.convertAndSend("backtone.queue",surveyRequestDTOString);



    }
}
